package com.demo.xmtx.mapper;

import com.demo.xmtx.entity.Order;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface OrderMapper {

  @Insert("INSERT INTO orders (user_id, product_id, quantity, status) " +
      "VALUES (#{userId}, #{productId}, #{quantity}, #{status})")
  @Options(useGeneratedKeys = true, keyProperty = "id")
  void insertOrder(Order order);

  @Select("SELECT * FROM orders WHERE id = #{id}")
  Order selectOrderById(Long id);

  @Delete("DELETE FROM orders WHERE id = #{id}")
  void deleteOrderById(Long id);

  @Update("UPDATE orders SET status = #{status} WHERE id = #{id}")
  void updateOrderStatus(Long id, String status);
}
